<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .el-page-header__content{
            color: white;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div id="app">
    <el-page-header  @back="goBack" content="添加轮播图" style="background-color: #0095d7;color: white;
    line-height: 60px" >
    </el-page-header>

    <el-upload
            action="/upload"
            name="pic"
            limit="1"
            list-type="picture-card"
            :on-success="handleSuccess"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
        <i class="el-icon-plus"></i>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
  <!--  <input type="button" value="添加" @click="send()">-->
    <el-button type="success" @click="insert()">添加轮播图</el-button>

</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
   let v = new Vue({
        el: '#app',
        data: function() {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                url:""
            }
        },
       methods:{
            insert(){
                if(v.url==""){
                    v.$message.error("请添加图片")
                    return;
                }
                axios.get("/banner/insert?url="+v.url).then(function (response) {
                   location.href="/admin.html"
                })
            },

            handleSuccess(response,file,fileList){
                //response 就行相当于。data
                v.url=response

            },
            goBack(){
                history.back()//返回上一页面
            },
           handleRemove(file, fileList) {
               console.log(file, fileList);
               axios.get("/remove?url="+v.url).then(function () {
                   v.$message("服务器图片删除完成");
                   v.url="";
               })
           },
           handlePictureCardPreview(file) {
               this.dialogImageUrl = file.url;
               this.dialogVisible = true;
           }
       },

    })
</script>
</html>